{include file='public/header' /}



<body>



<div class="x-nav">

      <span class="layui-breadcrumb">

        <a href="">首页</a>

        <a href="">管理员管理</a>

       
        <a><cite>管理员列表</cite></a>
      
      </span>

    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">

        <i class="layui-icon" style="line-height:30px">ဂ</i></a>

</div>





<div class="x-body"  style="padding: 0px">



    <table class="layui-hide" id="test" lay-filter="test"></table>

   

</div>



<script type="text/html" id="toolbarDemo">

      <div class="layui-form-item"> 
    
        <form class="layui-form" action="" lay-filter="search">
        <a class="layui-btn"  onclick="x_admin_show('添加管理员','{:url(\'add\')}')"><i class="layui-icon"></i>添加管理员</a>
         <input type="text" name="name"  placeholder="请输入账号搜索" autocomplete="off" class="layui-btn layui-btn-primary">

          <div class="layui-inline">
            <button class="layui-btn"  lay-event="searchBarFunc"><i class="layui-icon">&#xe615;</i></button>
          </div>

  </form>
</div>
</script>



<script type="text/html" id="barDemo">

  <div class="layui-btn-group">

      <button type="button" class="layui-btn" lay-event="edit">编辑</button>
      
      {{#  if(d.id > 1){ }}
      <button type="button" class="layui-btn layui-btn-danger" lay-event="del">删除</button>
      {{#  } }}

      
      
  </div>

</script>


<script type="text/html" id="switchTp">

      <input type="checkbox" name="禁用" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sxjFunc" {{ d.is_disable == 0 ? 'checked' : '' }}>

</script>



<script type="text/html" id="roleinfo">

    {{#  if(d.type == 1){ }}

      <span class="layui-btn layui-btn-normal layui-btn-xs">超级管理员</span>

    {{#  } }}


    {{#  if(d.type == 2){ }}

        {{#  if(d.roleinfo){ }}

           <span class="layui-btn layui-btn-xs">{{d.roleinfo.name}}</span> 

        {{#  } }}

    {{#  } }}

</script>








<style type="text/css">

  /*{# 设置table每一行的height #}*/

  .layui-table-cell {

   height: 50px;

   line-height: 50px;

  }

 </style>

<script>

layui.use('table', function(){

  var table = layui.table

  ,form = layui.form;

  //第一个实例

  table.render({

    elem: '#test'

    ,height:'full-100'

    ,title:'后台账号列表'

    ,url: "{:url('gList')}" //数据接口

    ,page: true //开启分页

    ,limit:30

    ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板

    ,cols: [[ //表头

      // {type:'checkbox', fixed: 'left'}


       {field: 'account', title: '登录账号',fixed: 'left'}


      ,{field: 'type', title: '角色',templet: '#roleinfo'}

      ,{field: 'is_disable', title: '是否禁用', templet: '#switchTp',sort: true, unresize: true}

      ,{field: 'create_time', title: '创建时间',  sort: true,hide:false}

      ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}

    ]]

  });



  //监听上下架操作

  form.on('switch(sxjFunc)', function(obj){

    var is_xj = obj.elem.checked?0:1;

    var is_xj_str = obj.elem.checked?'已启用':'已禁用';

    var gId = this.value;

    if (gId == 1) {

        if (is_xj == 0) {
              obj.elem.checked = false;
          }else{
              obj.elem.checked = true;
          }
          layer.tips('初始超级管理员不可禁用', obj.othis);
          form.render('checkbox')

        return 1;
    }

    $.post("{:url('editSxj')}",{id:this.value,is_xj:is_xj},function (res) {

            layer.tips(is_xj_str, obj.othis);

             

    })

  });


  

  //监听行工具事件

  table.on('tool(test)', function(obj){

    var data = obj.data;

    if(obj.event === 'del'){

      layer.confirm('确定删除？', function(index){

         $.post("{:url('delGood')}",{id:data.id},function (res) {

                if(res == 1){

                     obj.del();

                     layer.msg('删除成功', {icon: 1});

                }else {

                    layer.msg('删除失败!',{icon:0,time:1000});

                }

            })

      });


    } else if(obj.event === 'edit'){

        x_admin_show('编辑管理员信息','{:url(\'edit\')}?id='+obj.data.id);

    }
  });



 //头工具栏事件

  table.on('toolbar(test)', function(obj){

         if(obj.event === 'searchBarFunc'){

              var data = form.val('search');
            
              table.reload('test',{
                  url: "{:url('gList')}",

                  page: {
                    curr: 1 //重新从第 1 页开始
                  }

                 ,where: data
                 ,done: function(res, curr, count){
                    form.val('search', data);

                 }
              })


        }

  });

});

</script>







</body>





</html>